import request from '@/utils/request'

/**
 * GitHub 配置管理
 */

// 获取 GitHub 配置列表
export function getGitHubConfigs() {
  return request({
    url: '/static_web/api/github/cfg/',
    method: 'get'
  })
}

// 获取单个 GitHub 配置
export function getGitHubConfig(id) {
  return request({
    url: `/static_web/api/github/cfg/${id}/`,
    method: 'get'
  })
}

// 创建 GitHub 配置
export function createGitHubConfig(data) {
  return request({
    url: '/static_web/api/github/cfg/',
    method: 'post',
    data
  })
}

// 更新 GitHub 配置
export function updateGitHubConfig(id, data) {
  return request({
    url: `/static_web/api/github/cfg/${id}/`,
    method: 'put',
    data
  })
}

// 删除 GitHub 配置
export function deleteGitHubConfig(id) {
  return request({
    url: `/static_web/api/github/cfg/${id}/`,
    method: 'delete'
  })
}

/**
 * GitHub 部署
 */

// 检查 GitHub 部署冲突
export function checkGitHubConflict(websiteId, data) {
  return request({
    url: `/static_web/api/github/deploy/${websiteId}/`,
    method: 'post',
    data: {
      ...data,
      check_only: true
    }
  })
}

// 部署网站到 GitHub
export function deployToGitHub(websiteId, data) {
  return request({
    url: `/static_web/api/github/deploy/${websiteId}/`,
    method: 'post',
    data
  })
}

// 获取 GitHub 部署历史
export function getGitHubDeploymentHistory(websiteId) {
  return request({
    url: `/static_web/api/github/history/${websiteId}/`,
    method: 'get'
  })
}

// 从 GitHub 拉取代码到本地
export function pullFromGitHub(websiteId) {
  return request({
    url: `/static_web/api/github/pull/${websiteId}/`,
    method: 'post'
  })
}
